#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct TrieNode
{
    /* data */
    int is_word;
    struct TrieNode *children[26];
} Trie;

Trie *createTrie()
{
    Trie *node = (Trie *)malloc(sizeof(Trie));
    if (NULL == node)
    {
        printf("malloc err");
        exit(1);
    }
    for (int i = 0; i < 26; i++)
    {
        node->children[i] = NULL;
        node->is_word = 0;
    }
    return node;
}

void addTrie(char *str, Trie *node)
{
    Trie *head = node;
    int i = 0;
    while (str[i] != '\0')
    {
        /* code */
        int index = str[i] - 'a';
        if (head->children[index] == NULL)
        {
            head->children[index] = createTrie();
        }
        head = head->children[index];
        i++;
    }
    head->is_word = 1;

}

int searchTrie(char *str, Trie *node)
{
    Trie *head = node;
    int i = 0;
    while (str[i] != '\0')
    {
        /* code */
        int index = str[i] - 'a';
        if (head->children[index] == NULL)
        {
            // printf("i = %d\n",i);
            // printf("index = %d\n",index);
            printf("err nothing\n");
            return -1;
        }
        head = head->children[index];
        i++;
    }
    if (head->is_word == 1)
    {
        printf("1\n");
        return 1;
    }
    else
    {
        printf("-1\n");
        return -1;
    }
    return -1;
}

void main()
{
    // for(int i=0;i<=10;i++) {
    //     printf("%d\n",i);
    // }
    Trie *node = createTrie();
    addTrie("abcd", node);
    addTrie("qwe", node);
    addTrie("abce", node);
    searchTrie("abc",node);
    searchTrie("abcdefg",node);
    searchTrie("abcde",node);
    searchTrie("abcd",node);

   
}